package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;
import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.OperatingSystemJDBCTemplate;
import ch.zbw.pra.sysventory.model.OperatingSystem;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class OperatingSystemDataAccessObject implements Serializable {

	private static final long serialVersionUID = 5151813868495101137L;
	private ApplicationContext context;
	private OperatingSystemJDBCTemplate operatingSystemJDBCTemplate;

	public OperatingSystemDataAccessObject() {
		context = DatabaseUtils.getContext();
		operatingSystemJDBCTemplate = (OperatingSystemJDBCTemplate)context.getBean("operatingsystem");
	}

	public List<OperatingSystem> getAllOperatingSystemFromDatabase() {
		List<OperatingSystem> operatingSystem = operatingSystemJDBCTemplate.listOperatingSystem();
		return operatingSystem;
	}

	public OperatingSystem getOperatingSystemFromComputer(Integer computerId) {
		OperatingSystem operatingSystem = operatingSystemJDBCTemplate.readOperatingSystemFromComputer(computerId);
		if(null == operatingSystem) {
			operatingSystem = new OperatingSystem();
		}
		return operatingSystem;
	}

	public Integer writeOperatingSystemToDatabase(OperatingSystem operatingSystem, Integer computerId) {
		Integer operatingSystemId = operatingSystemJDBCTemplate.insertOperatingSystem(operatingSystem, computerId);
		return operatingSystemId;
	}

}
